<template>
    <div class="year">
        <div class="top">
            <p class="title">年度游客量对比</p>
            <p class="bg"></p>
        </div>
        <div ref="chartRef" class="chart"></div>
    </div>
</template>

<script setup lang="ts">
import * as echarts from 'echarts';
import { ref , onMounted } from 'vue';

const chartRef = ref(null);

onMounted(() => {
    let myChart = echarts.init(chartRef.value);
    myChart.setOption({
        title: {
            text: '散点图',
            textStyle: {
                color: '#fff',
                fontSize: 16
            },
            left: 'center',
            top: 30
        },
        tooltip: {
            trigger: 'axis',
            
            backgroundColor: '#FFF'
        },
        legend: {
            data: ['游客数量'],
            textStyle: {
                color: '#fff'
            },
            left: 'center'
        },
        xAxis: {
            type: 'category',
            data: [],
            boundaryGap: false,

        },
        yAxis: {
            type: 'value',

        },
        series: [
            {
            data: [120, 270, 150, 180, 350, 260, 230,143,254,235,452,432,424,2],
            type: 'scatter',
            smooth: true,
            
            showBackground: true,
            backgroundStyle: {
                color: {
                    type: 'bar',
                    x: 0,
                    y: 0,
                    x2: 0,
                    y2: 1,
                    colorStops: [{
                        offset: 0, color: '#0099ff' // 0% 处的颜色
                    }, {
                        offset: 1, color: 'blue' // 100% 处的颜色
                    }],
                    global: false // 缺省为 false
                    }
            },
            itemStyle: {
                borderRadius: 10,
                color: () => {
                    const arr = ['red','orange','yellow','green','skyblue','blue','purple'];
                    return arr[Math.floor(Math.random() * arr.length)]
                },
                
            },

            },
        ],
    });
})
</script>

<style scoped lang="scss">
.year {
    width: 100%;
    height: 100%;
    background: url(../images/dataScreen-main-lb.png);
    background-repeat: no-repeat;
    background-size: 100% 100%;
    margin: 0 10px;
    margin-right: 20px;
    margin-top: 10px;
    .top {
        margin-left: 20px;
        .title {
            color: #fff;
            font-size: 20px;
        }
        .bg {
            background: url(../images/dataScreen-title.png) no-repeat;
            background-size: 100% 100%;
            width: 68px;
            height: 7px;
            margin-top: 10px;
        }
    }
    .chart {
        height: calc(100% - 30px);
    }
}
</style>